package com.qyer.search.filter;

import static com.qyer.search.model.QyerPlace.buildCountry;
import static com.qyer.search.model.lastminute.SKU.naSKU;

import com.qyer.search.model.Channel;
import com.qyer.search.model.SearchParameterOrigin;
import com.qyer.search.model.lastminute.SKU;
import org.apache.commons.collections4.CollectionUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by tangzheng on 16/3/7.
 */
public class ChannelFilter extends AbstractFilter{
  public ChannelFilter(Object[] conditions) {
    super(conditions);
  }

  @Override public boolean isValid(Map<String, Object> dataMap, SearchParameterOrigin searchParameterOrigin) {

    Set<String> strings = new HashSet<>();
    int size = conditions.length;
    for(int i = 0; i < size; i++){
      strings.add(String.valueOf(conditions[i]).trim());
    }
    int id = Integer.valueOf(String.valueOf(dataMap.get(SKU.FIELD_ID)));
    List<Map<String, Object>> listedData = (List<Map<String, Object>>) dataMap.get(SKU.FIELD_CHANNELS);
    if (CollectionUtils.isNotEmpty(listedData)) {
      for (Map<String, Object> map : listedData) {
        strings.remove(String.valueOf(map.get(Channel.FIELD_NAME)));
      }
    }
    if(strings.size() == 0)
      return true;

    //logWarning(naSKU(id), searchParameterOrigin, null);
    return false;
  }
}
